<template>
	<view>
		<view class="list" v-for="item in list" :key="item.id">
			<view class="header">
				<span>{{item.title}}</span>
				<span>时长：{{item.expire}}分钟</span>
			</view>
			<view class="item">
				<span>题目总数{{item.question_count}}</span>
				<span>总分数：{{item.total_score}}</span>
				<span>及格分：{{item.expire}}</span>
			</view>
			<view class="button">
				<u-button type="primary" class="buttond" @click="kaoshi(item.id)">参加考试</u-button>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getListt
	} from "@/api/user.js"
	export default {
		data() {
			return {
				list: [],
				queryModel: {
					page: 1,
					limit: 10
				},
				count: 0
			}
		},
		onLoad() {
			this.getdata()
		},
		onPullDownRefresh:function(){
			this.queryModel.page=1
			this.list=[]
			setTimeout(()=>{
				uni.stopPullDownRefresh()
				this.getdata()
			})
		},
		onReachBottom:function(){
			if(this.queryModel.page>=this.count){
				console.log(1);0.
				uni.showToast({
					title:"到最后一页了",
					duration:500,
				})
			}else{
				
				this.queryModel.page++
				this.getdata()
			}
		},
		methods: {
			//考试
			kaoshi(type){
				let that=this
				uni.showModal({
					title: '提示',
					content: '是否要开始考试',
					success: function (res) {
						if (res.confirm) {
							that.$router.push({
								path:"/pages/test-detail/test-detail",
								query:{
									type:type
								}
							})
							
						} else if (res.cancel) {
							uni.showToast({
								title:"已取消",
								duration:500,
							})
						}
					}
				});
			},
			
			async getdata() {
				const res = await getListt(this.queryModel)
				console.log(res);
				if (res.code == "20000") {
					// this.list = res.data.rows
					this.count=Math.ceil(res.data.count=res.data.rows)
					this.list=[...this.list,...res.data.rows]
				}
				console.log(res.data.rows);
			}
		}
	}
</script>

<style scoped lang="scss">
	* {
		box-sizing: border-box;
	}

	.list {
		width: 750rpx;
		height: 250rpx;
		background-color: white;
		border-bottom: 10rpx solid red;

		.header {
			width: 750rpx;
			height: 70rpx;
			background-color: white;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding-left: 50rpx;
			padding-right: 30rpx;

			span:nth-child(1) {
				color: #333;
				font-size: 34px;
				line-height: 1.8;
				font-weight: 700;
			}

			span:nth-child(2) {
				color: #dc3545;
				font-size: 27rpx;
			}
		}

		.item {
			width: 750rpx;
			height: 50rpx;
			background-color: white;
			display: flex;
			align-items: center;
			justify-content: space-between;

			span:nth-child(1) {
				padding-left: 50rpx;
				color: #333;
				font-size: 20px;
			}

			span:nth-child(3) {
				padding-right: 50rpx;
				color: #333;
				font-size: 20px;
			}
		}

		.button {
			width: 100%;
			height: 130rpx;
			padding-left: 647rpx;
			padding-top: 60rpx;
			background-color: white;

			.buttond {
				width: 100rpx;
				height: 70rpx;
				border-radius: 10rpx;
				background-color: #5CCC84;

			}

		}
	}
</style>
